package com.chief.hadoop.mr.outputFormat;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowMapper extends Mapper<LongWritable, Text, Text, FlowBean> {

    FlowBean flowBean = new FlowBean();
    Text text = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] split = line.split("\t");

        flowBean.setCnt(1);
        flowBean.setTotal(Long.parseLong(split[split.length - 2]) + Long.parseLong(split[split.length - 3]));

        text.set(split[1]);

        context.write(text, flowBean);
    }
}
